﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace MapEditor
{
    public partial class DlgNewMap : UserControl
    {
        private InvokeCreateNewMap _createNewMap;
        private int _widthInTiles=25;
        private int _heightInTiles=25;
        private int _tileRadius=128;
        private string _mapName="Default Map";

        public int WidthInTiles
        {
            get { return _widthInTiles; }
            set { _heightInTiles = value; }
        }

        public int HeightInTiles
        {
            get { return _heightInTiles; }
            set { _heightInTiles = value; }
        }

        public int TileRadius
        {
            get { return _tileRadius; }
            set { _tileRadius = value; }
        }

        public string MapName
        {
            get { return _mapName; }
            set { _mapName = value; }
        }

        public DlgNewMap(InvokeCreateNewMap createNewMap)
        {
            InitializeComponent();

            _tileRadius = SLGameEngine.Consts.LastTileRadius;
            _heightInTiles = SLGameEngine.Consts.LastHightInTiles;
            _widthInTiles = SLGameEngine.Consts.LastWidthInTiles;
            _mapName = SLGameEngine.Consts.LastMapName;
    
            xTileRadius.Text = Convert.ToString(_tileRadius);
            xMapHeight.Text = Convert.ToString(_heightInTiles);
            xMapWidth.Text = Convert.ToString(_widthInTiles);
            xMapName.Text = _mapName;

            _createNewMap = createNewMap;
        }

        private void Button_Click_OK(object sender, RoutedEventArgs e)
        {
            _mapName = xMapName.Text;
            SLGameEngine.Consts.LastMapName = _mapName;

            try
            {
                _tileRadius = Convert.ToInt32(xTileRadius.Text);
                SLGameEngine.Consts.LastTileRadius = _tileRadius;
            }
            catch 
            { 
                MessageBox.Show("Please input a value number for Tile Radius");
                return;
            }

            try
            {
                _heightInTiles = Convert.ToInt32(xMapHeight.Text);
                SLGameEngine.Consts.LastHightInTiles = _heightInTiles;
            }
            catch 
            { 
                MessageBox.Show("Please input a value number for Map Height");
                return;
            }

            try 
            { 
                _widthInTiles = Convert.ToInt32(xMapWidth.Text);
                SLGameEngine.Consts.LastWidthInTiles = _widthInTiles;
            }
            catch 
            { 
                MessageBox.Show("Please input a value number for Map Width");
                return;
            }

            _createNewMap(true);
        }

        private void Button_Click_Cancel(object sender, RoutedEventArgs e)
        {
            _createNewMap(false);
        }
    }
}
